package com.wps.data
{
	import com.wps.data.DayInfo;
	import com.wps.data.DayResult;
	import com.wps.data.UserData;
	/**
	 * 
	 * 	所有数据的一个单例
	 */	
	public class NetData
	{
		private static var _netData: NetData;
		public static function get instance(): NetData
		{
			if(!_netData)
			{
				_netData = new NetData();
			}
			return _netData;
		}
		
//		public var users: Vector.<UserData>;
		public var days: Vector.<DayInfo>;
		
		public function NetData()
		{
			days = new Vector.<DayInfo>;
		}

		
		public function setResult(result: Array): void
		{
			for(var i:int = 0; i < result.length; i++)
			{
				var dayResult: Object = result[i];
				var date: Date = dayResult.date as Date;
				ProjectManager.workDays.push(date);
				var dayInfo: DayInfo = new DayInfo();
				dayInfo.dateIndex = i;
				dayInfo.date = date;
				dayInfo.usersResult = new Vector.<UserResult>();
				var graphData: Object = dayResult.graphData;
				for(var user: String in graphData)
				{
					var userResult: UserResult = new UserResult(user, graphData[user].timecount, graphData[user].taskcount);
					dayInfo.usersResult.push(userResult);
				}
				
				if(i == 0)
				{
					ProjectManager.users = new Vector.<String>();
					for(var user: String in graphData)
						ProjectManager.users.push(user);
				}
				this.days.push(dayInfo);
			}
		}
		
		public function importFormXml(obj: Object): void
		{
			ProjectManager.fillUsers();
			ProjectManager.fillWorkDays();
			var _days: Vector.<DayInfo> = new Vector.<DayInfo>();
			for(var i: int = 0; i < ProjectManager.dayCount; i++)
			{
				var day: DayInfo = new DayInfo();
				day.dateIndex = i;
				day.importFromXml();
				_days.push(day);
			}
			days = _days;
		}
		
		
		
	}
}